<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>#{bundle.bank}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form >
               <script type="text/javascript">  
                    function handleSaveBank(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgBank.hide();  
                        }  
                    }

                    function handleDeleteBank(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgDelBank.hide();  
                        }  
                    }
                    
                    function textOnKeyPress(e) {
                        var code = (e.keyCode ? e.keyCode : e.which);
                        if(code==13) {
                            cmdSearchBank.jq.click();
                            e.returnValue=false;
                            e.cancel =true;
                            e.preventDefault();
                        }
                    }

                </script>  

                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}"
                                         icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(461,'INS;')}"
                                         action="#{bankBean.newData()}"  
                                         oncomplete="dlgBank.show()" process="@this"
                                         update=":#{utilityBean.findClientId('displayBank')}"> 
                            <pe:resetEditableValues for="displayBank"/>
                        </p:commandButton>

                        <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgBank.show()"
                                         actionListener="#{bankBean.openData()}"
					rendered="#{menuBean.cekButtonAccess(461,'OPN;')}"
                                         icon="ui-icon-disk" 
                                         update=":#{utilityBean.findClientId('displayBank')}" > 
                        </p:commandButton>

                        <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                         onclick="dlgDelBank.show()" rendered="#{menuBean.cekButtonAccess(461,'DEL;')}" /> 

                        <p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/>
                    </p:toolbarGroup>
                </p:toolbar>
                <br/>

                <p:dataTable var="bank" value="#{bankBean.banks}" id="dtBanks" resizableColumns="true"
                             rowIndexVar="noUrut" selection="#{bankBean.selectedData}" selectionMode="single" 
                             rowKey="#{bank.bankId}" sortBy="#{bank.bankName}" >
                     <p:column style="width: 12px;">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                 </p:column>
                    <p:column style="width:auto" sortBy="#{bank.bankName}">
                        <f:facet name="header">#{bundle.bank}</f:facet>
                        <h:outputText value="#{bank.bankName}" />
                    </p:column>
                    
                    <p:column style="width:auto" >
                        <f:facet name="header">#{bundle.aliasName}</f:facet>
                        <h:outputText value="#{bank.alias}" />
                    </p:column>
                    
                    <p:column style="width:100px;" >
                        <f:facet name="header">#{bundle.currency}</f:facet>
                        <h:outputText value="#{bankBean.getCurrName(bank.currencyId)}" />
                    </p:column>
                    
                    <p:column style="width:100px;" >
                        <f:facet name="header">#{bundle.glaccnt}</f:facet>
                        <h:outputText value="#{bankBean.getGLName(bank.glaccountId)}" />
                    </p:column>
                    
                </p:dataTable>

                <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                                 header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelBank"> 
                    <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                        <f:facet name="footer">
                            <p:commandButton value="#{bundle.btnYes}" update="dtBanks" process="@this"
                                             oncomplete="handleDeleteBank(xhr, status, args)"  
                                             actionListener="#{bankBean.delete()}" />  
                            <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelBank.hide()" type="button" />
                        </f:facet>
                    </h:panelGrid>
                </p:confirmDialog>
            </h:form>
            <p:dialog header="#{bundle.bank}" widgetVar="dlgBank" closable="true" dynamic="true" modal="true" appendToBody="true">
                    <p:ajax event="close" listener="#{bankBean.handleClose}" immediate="true"/>
                    <h:form>
                    <h:panelGrid id="displayBank" columns="3" styleClass="addELIT">
                        <h:outputLabel value= "#{bundle.bank}" /><h:outputLabel value= ":" />
                        <p:inputText rendered="#{bankBean.insertedData!=null}" value="#{bankBean.insertedData.bankName}" 
                                         required="true" label="#{bundle.bank}" style="width: 150px" />  
                        
                        <h:outputLabel value= "#{bundle.aliasName}" /><h:outputLabel value= ":" />
                        <p:inputText rendered="#{bankBean.insertedData!=null}" value="#{bankBean.insertedData.alias}" 
                                         required="true" label="#{bundle.aliasName}" style="width: 150px" />
                        
                        <h:outputLabel value= "#{bundle.currency}" /><h:outputLabel value= ":" />
                        <p:selectOneMenu value="#{bankBean.insertedData.currencyId}" style="width: 150px" 
                                         required="true" rendered="#{bankBean.insertedData!=null}">
                                <f:selectItem itemLabel="#{bundle.Select} #{bundle.currency}" itemValue="" />
                                <f:selectItems value="#{bankBean.avaibleCurrency}" />
                        </p:selectOneMenu> 

                        <p:outputLabel for="bankGlaccount" value= "#{bundle.glaccnt}" /><h:outputLabel value= ":" />
                        <p:selectOneMenu  value="#{bankBean.glaccount}" rendered="#{bankBean.insertedData!=null}" 
                                                  style="width: 300px;" var="glacc1" converter="glaccnt" id="bankGlaccount" required="true">
                            <f:selectItem rendered="#{bankBean.glaccount!=null}" itemLabel="#{bankBean.glaccount.accountName}" itemValue="#{bankBean.glaccount}" />
                            <f:selectItems value="#{bankBean.avblAkun}" var="gl" itemLabel="#{gl.accountName}" itemValue="#{gl}" />
                            <p:column>#{glacc1.accountNo}</p:column>
                            <p:column>#{glacc1.accountName}</p:column>
                        </p:selectOneMenu>
                        
                    </h:panelGrid>

                    <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                        <f:facet name="footer">
                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{bankBean.save()}" rendered="#{menuBean.cekButtonAccess(461,'UPD;')}"
                                             update=":#{utilityBean.findClientId('dtBanks')}"
                                             oncomplete="handleSaveBank(xhr, status, args)"/>
                            <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgBank.hide()" icon="ui-icon-document" immediate="true"/>
                        </f:facet>
                    </h:panelGrid>
                        </h:form>
                </p:dialog> 
            
       </ui:composition>     
    </h:body>
</html>
